<?php
App::uses('RssComponent', 'Controller/Component');
App::uses('Controller', 'Controller');
App::uses('ComponentCollection', 'Controller');

class RssComponentTest extends CakeTestCase {
	public function setUp(){
		parent::setUp();
		// Setup our component and take test controller
		$Collection = new ComponentCollection();
		$this->RssComponent = new RssComponent($Collection);
	}

	public function testConstruct(){
		$this->assertNotNull($this->RssComponent);
		$this->assertInstanceOf('RssComponent',$this->RssComponent);
	}

	public function testParseForRSS2(){
		$url = "http://rss.rssad.jp/rss/itmatmarkit/rss.xml";//it's RSS 2.0
		$result = $this->RssComponent->parse($url);

		$this->assertArrayHasKey('rss', $result);
		$this->assertArrayHasKey('title', $result['rss']['channel']);
		$this->assertArrayHasKey('pubDate', $result['rss']['channel']);
		$this->assertArrayHasKey('link', $result['rss']['channel']);
		$this->assertArrayHasKey('description', $result['rss']['channel']);
		$this->assertArrayHasKey('title', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('link', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('description', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('pubDate', $result['rss']['channel']['item'][0]);
	
		$this->assertNotEmpty($result);

	}

	public function testParseForRSS1(){
		$url = "http://itpro.nikkeibp.co.jp/rss/ittrend.rdf";//it's RSS 1.0
		$result = $this->RssComponent->parse($url);

		$this->assertNotEmpty($result);
		$this->assertArrayHasKey('RDF', $result);
		$this->assertArrayHasKey('title', $result['RDF']['channel']);
		$this->assertArrayHasKey('dc:date', $result['RDF']['channel']);
		$this->assertArrayHasKey('link', $result['RDF']['channel']);
		$this->assertArrayHasKey('description', $result['RDF']['channel']);
		$this->assertArrayHasKey('title', $result['RDF']['item'][0]);
		$this->assertArrayHasKey('link', $result['RDF']['item'][0]);
		$this->assertArrayHasKey('description', $result['RDF']['item'][0]);
		$this->assertArrayHasKey('@rdf:about', $result['RDF']['item'][0]);
		$this->assertArrayHasKey('dc:date', $result['RDF']['item'][0]);
	}


}
